package org.kfive.nova.io.netty.protobuf;

/*
 * Copyright (c) 2016 lizhanwu.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/*
 * <p>
 * OrderClientHandler.java
 *
 * Application:
 * NO
 *
 * Limited:
 * NO
 *
 * Warning:
 * NO
 *-----------------------------------------------------------------------------
 *         VERSION       DATE            BY       CHANGE/COMMENT
 * -----------------------------------------------------------------------------
 *          1.0      2016-12-210:47     lizhanwu      create
 * -----------------------------------------------------------------------------
 * </p>
 */
public class OrderClientHandler extends SimpleChannelInboundHandler<org.kfive.nova.io.netty.protobuf.OrderOuterClass.Order> {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
        //生成订单地址
        org.kfive.nova.io.netty.protobuf.OrderOuterClass.Address.Builder addreddBuilder = org.kfive.nova.io.netty.protobuf.OrderOuterClass.Address.newBuilder();
        addreddBuilder.setAddress("北京市东城区东四南大街157号仁和云健康8楼");
        addreddBuilder.setId(1);
        //生成产品
        org.kfive.nova.io.netty.protobuf.OrderOuterClass.Product.Builder productBuilder = org.kfive.nova.io.netty.protobuf.OrderOuterClass.Product.newBuilder();
        productBuilder.setId(1);
        productBuilder.setName("感冒灵颗粒");
        productBuilder.setPrice(100);
        org.kfive.nova.io.netty.protobuf.OrderOuterClass.Order.Builder orderBuilder = org.kfive.nova.io.netty.protobuf.OrderOuterClass.Order.newBuilder();
        orderBuilder.setId(1);
        orderBuilder.setAddress(addreddBuilder.build());
        orderBuilder.setAmount(100);
        orderBuilder.addProducts(productBuilder.build());
        ctx.writeAndFlush(orderBuilder.build());
        System.out.println("client send successed");
    }

    protected void channelRead0(ChannelHandlerContext ctx, org.kfive.nova.io.netty.protobuf.OrderOuterClass.Order msg) throws Exception {

    }
}
